#!/usr/bin/env python
#
# Copyright 2011 Justin Bruce Van Horne <justinvh@gmail.com>
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#  http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

""" Handles texture browsing while in editor.

 TextureBrowser: Loads materials and displays tiles for selection.
"""

import pyglet
import json
import os

from time import time
from pyglet.window import key
from shared import *

from engine import camera

from ui import *

WIDTH, HEIGHT = (300, 300)


class EntityEditor(pyglet.window.Window):
    """Handles editing entities."""

    def __init__(self):
        super(EntityEditor, self).__init__(WIDTH, HEIGHT)
        # Camera
        self.camera = camera.FlatCamera(0, 0, self.width, self.height)

        # Theme
        self.theme = Theme(THEME_RES_PATH)
        self.frame = Frame(self.theme, w=300, h=300, camera=self.camera)
        self.push_handlers(self.frame)
        self.dialogue = Dialogue('Menu', w=300, x=0, y=300,
            content=FlowLayout(w=300, hpadding=0, children=[
                        Button('New '),
                        Button('Load'),
                        Button('Save'),
                        Button('Exit'),
                        Button('Reload Textures'),
                ]),
            )

        self.frame.add(self.dialogue)


    def set_map_editor(self, editor):
        """Set the map editor."""
        self.map_editor = editor

    def on_mouse_motion(self, x, y, dx, dy):
        self.mx, self.my = x, y

    def on_draw(self):
        """Draw the tile list."""
        self.clear()
        self.frame.draw()
